package com.jiawa.wiki.controller;

import com.jiawa.wiki.req.DocQueryReq;
import com.jiawa.wiki.req.DocSaveReq;
import com.jiawa.wiki.resp.CategoryQueryResp;
import com.jiawa.wiki.resp.DocQueryResp;
import com.jiawa.wiki.resp.CommonResp;
import com.jiawa.wiki.resp.PageResp;
import com.jiawa.wiki.service.DocService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/doc")
public class DocController {

    @Resource
    private DocService docService;

    @GetMapping("/all/{ebookId}")
    public CommonResp all(@PathVariable Long ebookId){
        CommonResp commonResp = new CommonResp();
        List<DocQueryResp> list = docService.all(ebookId);
        commonResp.setContent(list);
        return commonResp;
    }



    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody DocSaveReq req) {
        CommonResp resp = new CommonResp<>();
        docService.save(req);
        return resp;
    }

    @DeleteMapping("/delete/{ids}")
    public CommonResp delete(@PathVariable String  ids){
        CommonResp commonResp = new CommonResp();
        List<String> list = Arrays.asList(ids.split(","));
        docService.delete(list);
        return commonResp;
    }
    @GetMapping("/findContent/{id}")
    public CommonResp findContent(@PathVariable Long  id){
        CommonResp commonResp = new CommonResp();
        String content = docService.findContent(id);
        commonResp.setContent(content);
        return commonResp;
    }



}
